import store from '../store'
function getUploadToken(data, view) {
  console.log(store, 'store')
  return store
    .dispatch('proxyAction', {
      name: 'getUploadToken',
      message: false,
      data
    })
}

function getFileKey(path, signature, fileName) {
  const suffix = getFileSuffix(fileName);

  let prefix = signature
    .replace(/[\'\"\\\/\b\f\n\r\t]/g, '')
    .replace(/[/[\@\#\$\%\^\&\*\(\)\{\}\:\"\L\<\>\?\[\]\+\-\=]/g, '');
  prefix = `${path + new Date().getTime().toString() + prefix.substr(prefix.length - 10, 10)}`;

  return `${prefix}.${suffix}`;
}

function getFileSuffix(fileName) {
  const start = fileName.lastIndexOf('.');
  const {
    length
  } = fileName;
  const suffix = fileName.substring(start + 1, length);
  return suffix.toLowerCase();
}

export default {
  getUploadToken,
  getFileKey,
  getFileSuffix
}